$(function () {





    function addC() {
        $(".p1").addClass("p1-active");
        $(".t1,.t2").addClass("t-active");
    }


    if (window.localStorage && window.localStorage.TM == 1) {;
        $(".loading").fadeOut();
        addC();
        return false;
    }

    var l1 = document.getElementById("load");
    var ctx = l1.getContext('2d');

    var loadTimer;
    var progress = 0;
    var x = 0;
    var sum = 0;

    function loadDraw() {
        progress += 2;
        l1.width = l1.width;
        ctx.lineWidth = 5;
        ctx.lineCap = "round";
        ctx.beginPath();
        ctx.strokeStyle = "#43277b";
        ctx.arc(55, 55, 50, 0, 2 * Math.PI);
        ctx.stroke();
        ctx.beginPath();
        ctx.strokeStyle = "#fdf8e3";
        ctx.arc(55, 55, 50, -90 * Math.PI / 180, (progress * 3.6 - 90) * Math.PI / 180);
        ctx.stroke();
        if (progress >= x) {
            cancelAnimationFrame(loadTimer);
            if (sum == $("img").length) {
                if (window.localStorage) {
                    window.localStorage.TM = 1;
                }
                $(".loading").addClass("hide");
                addC();
                setTimeout(function () {
                    $(".loading").fadeOut();
                }, 600);
            }
        } else {
            loadTimer = requestAnimationFrame(loadDraw)
        }
    }


    $("img").each(function () {
        var img = new Image();
        img.onload = function () {
            sum++;
            cancelAnimationFrame(loadTimer);
            x = Math.round(sum / $("img").length * 100);
            loadDraw();

        }
        img.src = $(this).attr('src');
    });
});